<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
    var id = 1;
    db.transaction(function (tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
        tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "菜鸟教程")');
        // 使用外部变量，执行时会将变量数组中的值依次替换前边的问号位置
        tx.executeSql('INSERT INTO LOGS (id,log) VALUES (?, ?)', [e_id, e_log]);

        // 查询和回调
        tx.executeSql('SELECT * FROM LOGS', [], function (tx, results) {
            var len = results.rows.length, i;
            var msg = "<p>查询记录条数: " + len + "</p>";
            document.querySelector('#status').innerHTML += msg;
            for (i = 0; i < len; i++){
                msg = "<p><b>" + results.rows.item(i).log + "</b></p>";
                document.querySelector('#status').innerHTML += msg;
            }
        }, null);
        tx.executeSql('DELETE FROM LOGS  WHERE id=1'); // 删除
        tx.executeSql('DELETE FROM LOGS WHERE id=?', [id]);
        tx.executeSql('UPDATE LOGS SET log=\'www.w3cschool.cc\' WHERE id=2'); // 更新
        tx.executeSql('UPDATE LOGS SET log=\'www.w3cschool.cc\' WHERE id=?', [id]);
    });
</script>
</body>
</html>